package leetcode.code1894;

public class Solution2 extends Solution1894 {

	@Override
	public int chalkReplacer(int[] chalk, int k) {
		int len = chalk.length;
		int total = 0;
		for (int i = 0; i < len; i++) {
			total += chalk[i];
			if (total > k) {
				return i;
			}
		}
		int mod = k % total;
		for (int i = 0; i < len; i++) {
			if (mod >= chalk[i]) {
				mod -= chalk[i];
			} else {
				return i;
			}
		}
		return -1;
	}

// 1,3,5,7
	public static void main(String[] args) {
		Solution2 so = new Solution2();
//		so.debug1();
		so.debug2();
//		System.out.println(Integer.MAX_VALUE);
//		System.out.println(Integer.MAX_VALUE + 10000);

	}

}
